import type { StorybookConfig } from "@storybook/vue3-vite";
import { resolve } from 'path'
import { fileURLToPath, URL } from 'node:url'

const config: StorybookConfig = {
  // stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
  stories: [
    "../storybook/**/*.mdx",
    // "../storybook/**/*.stories.@(js|jsx|mjs|ts|tsx)",
    "../src/components/**/*.stories.@(js|jsx|mjs|ts|tsx)"
  ],
  addons: [
    "@chromatic-com/storybook", // 视觉回归测试
    "@storybook/addon-docs", // 自动生成文档
    "@storybook/addon-onboarding", // 新手引导
    "@storybook/addon-a11y", // 无障碍检查
    "@storybook/addon-vitest", // Vitest 测试集成
  ],
  framework: {
    name: "@storybook/vue3-vite",
    options: {},
  },
  core: {
    disableTelemetry: true,
  },
  staticDirs: ["../public"], // 挂整个目录，确保这里的路径指向你的 favicon 文件所在目录
  async viteFinal(config) {
    //   // 配置 Storybook 路径别名
    //   const alias = config.resolve?.alias;
    //   return alias; // 关键：复用主项目的 vite.config.js
    // 自定义 Vite 配置，例如别名、CSS 预处理器等
    return {
      ...config,
      resolve: {
        ...config.resolve,
        alias: {
          // 与你的 vite.config.js 保持一致
          "@": fileURLToPath(new URL('../src', import.meta.url)),
          "@set": fileURLToPath(new URL('../src/assets', import.meta.url)),
          "@cop": fileURLToPath(new URL('../src/components', import.meta.url)),
          "@view": fileURLToPath(new URL('../src/views', import.meta.url)),
          "@util": fileURLToPath(new URL('../src/utils', import.meta.url)),
          "@hook": fileURLToPath(new URL('../src/hooks', import.meta.url)),
          "@type": fileURLToPath(new URL('../src/types', import.meta.url)),
        },
      },
    }
  },
};

export default config;
